package com.insightg3.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;

public class QuickSearchActivity extends Activity {
	private EditText txtKeyword;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Spinner spinner = (Spinner)findViewById(R.id.cmdArea);
		ArrayAdapter adapter = ArrayAdapter.createFromResource(
				this, R.array.value_where, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		
		//initialization
		txtKeyword =  (EditText)findViewById(R.id.txtKeyword);
		((Button) findViewById(R.id.btnSearch)).setOnClickListener(mSearchListener);
		((Button) findViewById(R.id.btnClear)).setOnClickListener(mClearListener);
	}

	OnClickListener mSearchListener = new OnClickListener() {
		public void onClick(View v) {
			//編集エリアに追加データを表示する。
			Intent intent = null;
			String strArea = (((Spinner)findViewById(R.id.cmdArea)).getSelectedItem()).toString();
			
			if(strArea.equals("China")) {
				intent = new Intent( QuickSearchActivity.this, SearchResultActivity.class );
			} else {
				intent = new Intent( QuickSearchActivity.this, KakakuSearchResultActivity.class );
			}
            String searchkey = txtKeyword.getText().toString();
            CheckBox chkSelect = (CheckBox) findViewById(R.id.chkQuickAutoTranlation);
            if (chkSelect.isChecked()) {
               searchkey = AndroidUtils.getAutoTranslation(QuickSearchActivity.this, searchkey, strArea);
            }
            Log.d("quick search searchkey=", searchkey);
			intent.putExtra("SEARCH_KEY", searchkey);
			intent.putExtra("SEARCH_NO", "1");
			startActivity( intent );
		}
	};

	OnClickListener mClearListener = new OnClickListener() {
		public void onClick(View v) {
			txtKeyword.setText("");
			txtKeyword.setHint(getText(R.string.s_find_hit));
		}
	};
}
